# -*- coding: utf-8 -*-
# !/usr/bin/env python
from utils.mysql_utils import query_to_list


def query_host_group(env_id=''):
    sql_parameter = []

    if env_id:
        sql_fragment = "AND a.env_id = %s"
        sql_parameter.append(env_id)
    else:
        sql_fragment = ''

    sql = """
    SELECT a.*, b.sys_code_name as env_type_text, b.sys_code
    FROM elink_hosts_group a
    LEFT JOIN sys_code b ON a.env_type_code = b.sys_code AND b.sys_code_type = "env_type"
    WHERE a.status = 1
    %s
    """ %(sql_fragment)

    data = query_to_list(sql, sql_parameter)
    return data